<% include inc-head.ejs %>

<script>
    function clickGood(id){
        saveClickGoodBad(id,'good');
    }
    function clickBad(id){
        saveClickGoodBad(id,'bad');
    }

    function saveClickGoodBad(id,what){
        $.post("/index/savegoodbad",{id:id,what:what},function(data){
            data.flag && updateGoodBadNum(id,what);
        });
    }

    function updateGoodBadNum(id,what){
        var idx = 0 ;
        if(what == 'bad'){idx += 1;}
        var $lbl = $("#"+id).find("label").eq(idx);
        $lbl.text(parseInt($lbl.text(),10) + 1);
    }
</script>

<div style="width: 100%; height: 58px; background-color: #2d2d2d; color: grey">
    <div class="logo" style="float: left; width: 200px; text-align: center;">
        <a href="/" title="本站内容如有侵仅请联系管理员，我们会在第一时间删除">笑话集市</a>
    </div>
    <ul class="index_nav">
        <li><a href="/">每天更新</a></li>
        <li class="active"><a href="/month_ranking">月排行</a></li>
        <li><a href="/joke_gif">搞笑动画</a></li>
        <li><a href="/contribute">我要投稿</a></li>
    </ul>
</div>

<div style="width: 500px;margin-left: 200px; margin-top: 20px;">
    <% for(var i=0; i<jokes.length; i++) {%>

    <div class="well well-lg">
        <p><%= jokes[i].contribute_text %></p>
        <div style="float: right" id="<%=jokes[i].id%>">
            <a href="#" onclick="clickGood('<%=jokes[i].id%>')">好</a>(<label><%=jokes[i].contribute_good%></label>)
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="clickBad('<%=jokes[i].id%>')">差</a>(<label><%=jokes[i].contribute_bad%></label>)
        </div>

    </div>

    <% } %>

</div>

<% include inc-foot.ejs %>